package com.dks.repository.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dks.dto.TaskListDto;
import com.dks.mapper.TaskMapper;
import com.dks.models.Task;
import com.dks.repository.ITaskRepository;
import com.dks.result.Result;
import com.dks.result.ResultInfo;
import com.dks.result.ResultModel;
import com.dks.util.PageInfo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TaskRepository implements ITaskRepository {

    private TaskMapper taskMapper;

    @Autowired
    public TaskRepository(final TaskMapper taskMapperIn) {
        this.taskMapper = taskMapperIn;
    }

    @Override
    public Integer insert(Task task) {
        return taskMapper.insert(task);
    }

    @Override
    public Integer update(Task task) {
        return taskMapper.update(task);
    }

    @Override
    public Integer delete(Integer id) {
        return taskMapper.delete(id);
    }

    @Override
    public Task select(Integer id) {
        return taskMapper.select(id);
    }

    @Override
    public Integer cntByMap(Map<String, Object> map) {
        return taskMapper.cntByMap(map);
    }

    @Override
    public List<Integer> getByMap(Map<String, Object> map) {
        return taskMapper.getByMap(map);
    }

    @Override
    public List<Task> getByMapList(Map<String, Object> map) {
        return taskMapper.getByMapList(map);
    }

    @Override
    public Integer updateByCode(Task task) {
        return taskMapper.updateByCode(task);
    }

    @Override
    public Task selectByBfCode(String bfCode) {
        return taskMapper.selectByBfCode(bfCode);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取作业信息
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param:
     * @return:
     * @throw: 请描述异常信息
     */
    @Override
    public ResultModel<Object> getTaskInfo(Integer chapterId) {
        Map<String, Object> map = new HashMap<>();
        map.put("chapterId", chapterId);
        map.put("recStatus", 0);
        List<Task> taskList = taskMapper.getByMapList(map);
        return Result.makeResult(ResultInfo.SUCCESS, taskList);
    }

    /**
     * @Author: Ah Nan
     * @Description: 获取同学作业列表
     * @Date: 9:52 2020/4/23
     * @Modificd By:
     * @Param: taskId 作业id
     * @Param: pageNum 页码
     * @Param: pageSize 条数
     * @return:
     * @throw: 请描述异常信息
     */
    @Override
    public ResultModel<Object> getStudentTaskList(Integer taskId, Integer pageNum, Integer pageSize) {
        Map<String, Object> map = new HashMap<>();
        map.put("taskId",taskId);
        Page p = PageHelper.startPage(pageNum, pageSize);
        List<TaskListDto> taskListDtoList = taskMapper.getStudentTaskList(map);
        PageInfo<TaskListDto> list = new PageInfo<>(pageNum, pageSize, p.getTotal(), p.getPages(), taskListDtoList);
        return Result.makeResult(ResultInfo.SUCCESS, list);

    }


}
